﻿



CREATE  PROCEDURE [dbo].[balcon_GenListaBalanta2014]
	@An smallint   
	,@CodUnitate smallint
	,@categorie tinyint
	,@analitica bit
	,@cfm bit
	,@filtruJurnale varchar(500)
	,@DataStart datetime
	,@DataEnd datetime
	,@ptgc bit
	,@ContStart as TipCont
	,@ContEnd as TipCont
	,@Extinsa bit
	,@filtruSurseFinantare varchar(500)
	,@FiltruAnaliticPar TipCont
	,@useDataStart bit
AS

DECLARE @lDataStart as datetime
DECLARE @strDataStart as varchar(50), @strDataEnd as varchar(50)
DECLARE @tabela varchar(100)
DECLARE @strcategorie as varchar(10)
DECLARE @dataStartFunctie varchar(50)
DECLARE @laData varchar(50)
DECLARE @ultimaData datetime


IF @useDataStart = 1
	SET @lDataStart = @DataStart
ELSE
	SET @lDataStart = DATEADD(Day, 1-DAY(@DataEnd),@DataEnd)



DECLARE	@return_value int
PRINT('DECLARE @ContStart as TipCont,@ContEnd as TipCont
DECLARE @DataStart as datetime, @DataEnd as datetime
DECLARE @categorie as tinyint
DECLARE @analitica bit
DECLARE @cfm bit
DECLARE @jurnal varchar(1000)
DECLARE @pAn smallint
DECLARE @ptgc bit
DECLARE @CodUnitate smallint
DECLARE	@return_value int
')

PRINT('SET @DataStart = ''' + cast(@DataStart as varchar(20)) + '''')
PRINT('SET @DataEnd=''' + cast(@DataEnd as varchar(100)) + '''')
PRINT('SET @jurnal=''' + @filtruJurnale +'''')
PRINT('SET @categorie=' + cast(@categorie as varchar(100)))
PRINT('SET @ContStart=''' + cast(@ContStart as varchar(100)) +'''')
PRINT('SET @ContEnd =''' + cast(@ContEnd as varchar(100)) + '''')
PRINT('SET @cfm=' + cast(@cfm as varchar(100)))
PRINT('SET @analitica=' + cast(@analitica as varchar(100)))
PRINT('SET @pAn=' + cast(@An as varchar(100)))
PRINT('SET @ptgc=' + cast(@ptgc as varchar(100)))
PRINT('SET @CodUnitate=' + cast(@CodUnitate as varchar(100)))

IF @An=0
BEGIN
	IF @ptgc = 1
		EXEC	@return_value = [dbo].[balcon_GetBalantaTGC2014]
		@CodUnitate = @CodUnitate,
		@pDtDataStartUI = @lDataStart,
		@pDtDataEndUI = @DataEnd,
		@filtJurnal = @filtruJurnale,
		@pCategorie = @categorie,
		@pStrContStart = @ContStart,
		@pStrContEnd = @ContEnd,
		@pCfm = @cfm,
		@pAnalitica = @analitica,
		@pCfmRulaje = 1,
		@pTerminal = 0,
		@FiltruAnalitic = @FiltruAnaliticPar
	ELSE
		IF @Extinsa=1
			EXEC	@return_value = [dbo].[balcon_GetBalantaExtinsa2014]
			@CodUnitate = @CodUnitate,
			@pDtDataStartUI = @lDataStart,
			@pDtDataEndUI = @DataEnd,
			@filtJurnal = @filtruJurnale,
			@pCategorie = @categorie,
			@pStrContStart = @ContStart,
			@pStrContEnd = @ContEnd,
			@pCfm = @cfm,
			@pAnalitica = @analitica,
			@pCfmRulaje = 1,
			@pTerminal = 0,
			@SurseFinantare = @filtruSurseFinantare,
			@FiltruAnalitic = @FiltruAnaliticPar
		ELSE
			EXEC	@return_value = [dbo].[balcon_GetBalanta2014]
			@CodUnitate = @CodUnitate,
			@pDtDataStartUI = @lDataStart,
			@pDtDataEndUI = @DataEnd,
			@filtJurnal = @filtruJurnale,
			@pCategorie = @categorie,
			@pStrContStart = @ContStart,
			@pStrContEnd = @ContEnd,
			@pCfm = @cfm,
			@pAnalitica = @analitica,
			@pCfmRulaje = 1,
			@pTerminal = 0,
			@SurseFinantare = @filtruSurseFinantare,
			@FiltruAnalitic = @FiltruAnaliticPar
END
ELSE
		EXEC	@return_value = [dbo].[balcon_GetBalantaArh2014]
		@CodUnitate = @CodUnitate,
		@pDtDataStartUI = @lDataStart,
		@pDtDataEndUI = @DataEnd,
		@filtJurnal = @filtruJurnale,
		@pCategorie = @categorie,
		@pStrContStart = @ContStart,
		@pStrContEnd = @ContEnd,
		@pCfm = @cfm,
		@pAnalitica = @analitica,
		@pCfmRulaje = 1,
		@pTerminal = 0,
		@pAn = @An,
		@FiltruAnalitic = @FiltruAnaliticPar


GOTO Gata
EROARE:
	RAISERROR ('Eroare la generarea balantei',16,-1)
Gata: